package main //必须有个main包

import "fmt"

func swap_normal(a, b int) {
	a, b = b, a
	fmt.Printf("swap: a = %d, b = %d\n", a, b)
}

//通过一个函数交换a和b的内容
func main_normal() {

	a, b := 10, 20
	fmt.Printf("main: a = %d, b = %d\n", a, b)
	swap_normal(a, b) //变量本身传递，值传递（站在变量角度）
	fmt.Printf("main: a = %d, b = %d\n", a, b)
}

func swap_pointer(p1, p2 *int) {
	*p1, *p2 = *p2, *p1
	fmt.Printf("poniter-swap: a = %v, b = %v\n", *p1, *p2)
}

func main() {
	a, b := 10, 20
	fmt.Printf("poniter-main: a = %d, b = %d\n", a, b)
	swap_pointer(&a, &b) //地址传递
	fmt.Printf("poniter-main: a = %d, b = %d\n", a, b)
}
